/**
 * Implementation of Closure function
 *
 * author: Marcin Wachulski
 *
 */
#include "OK.h"
#include <set>
#include <algorithm>
#include <iterator>

void Closure(const AttributeSet &prefix, OAPair &oa_pair, FormalContext &local_fc) {
    oa_pair.second->data.insert(prefix.data.begin(), prefix.data.end());
    if (local_fc.data.size() > local_fc.processedNo) {
        OAPair &fc_last_p = local_fc.data.back();
        if (fc_last_p.first->data.size() == oa_pair.first->data.size()) {
            oa_pair.second->data.insert(fc_last_p.second->data.begin(),
                fc_last_p.second->data.end());
            local_fc.data.pop_back();
            delete fc_last_p.first;
            delete fc_last_p.second;
        }
    }
}